package com.tjsinfo.tjsoa.workTask.bo;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;

import com.tjsinfo.tjsoa.Dao.IHibernateDao;
import com.tjsinfo.tjsoa.Dao.IQbcDao;
import com.tjsinfo.tjsoa.common.ToolKit;
import com.tjsinfo.tjsoa.workTask.dao.ITDailyWorkTaskDAO;
import com.tjsinfo.tjsoa.workTask.vo.TDailyWorkTask;

public class TDailyWorkTaskBO implements ITDailyWorkTaskBO {
	
	private IHibernateDao hibernateDao;
	private IQbcDao qbcDao;	
	private ITDailyWorkTaskDAO workTaskDao;
	
	public IHibernateDao getHibernateDao() {
		return hibernateDao;
	}
	public void setHibernateDao(IHibernateDao hibernateDao) {
		this.hibernateDao = hibernateDao;
	}
	
	public IQbcDao getQbcDao() {
		return qbcDao;
	}
	public void setQbcDao(IQbcDao qbcDao) {
		this.qbcDao = qbcDao;
	}	
	
	public ITDailyWorkTaskDAO getWorkTaskDao() {
		return workTaskDao;
	}
	public void setWorkTaskDao(ITDailyWorkTaskDAO workTaskDao) {
		this.workTaskDao = workTaskDao;
	}

	public void save(TDailyWorkTask transientInstance) {
		// TODO Auto-generated method stub
		workTaskDao.save(transientInstance);
	}
	
	public Integer addWorkTask(TDailyWorkTask tdwt) {
		// TODO Auto-generated method stub
		return hibernateDao.save(tdwt);
	}

	public TDailyWorkTask findById(String id) {
		// TODO Auto-generated method stub
		return workTaskDao.findById(id);
	}	
	
	@SuppressWarnings("unchecked")
	public List<TDailyWorkTask> selectAll(Integer first, Integer max,String dividerUserid,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDailyWorkTask.class);
		detachedCriteria.add(Restrictions.eq("dividerUserid", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("beginTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, max, first).getItems();
		
	}
	
	public List<TDailyWorkTask> selectName(Integer first, Integer max,String dividerUserid,String personTypeName,String name,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDailyWorkTask.class);
		detachedCriteria.add(Restrictions.eq("dividerUserid", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		detachedCriteria.add(Restrictions.eq(personTypeName,name));
		List<Order> orderlist= new ArrayList<Order>();
		orderlist.add(Order.desc("beginTime"));
		return qbcDao.findPageByCriteria(detachedCriteria, orderlist, max, first).getItems();
	}	
	
	public Integer selectTotal(String dividerUserid,String personTypeName,String name,HttpServletRequest request) {
		// TODO Auto-generated method stub
		DetachedCriteria detachedCriteria = DetachedCriteria.forClass(TDailyWorkTask.class);		
		detachedCriteria.add(Restrictions.eq("dividerUserid", String.valueOf(ToolKit.getSessionUser(request).getUser_id())));
		if(name != null){
			detachedCriteria.add(Restrictions.eq(personTypeName,name));
		}
		
		return  qbcDao.getQueryNumber(detachedCriteria, "id");
	}
	public void update(TDailyWorkTask transientInstance) {
		// TODO Auto-generated method stub
		workTaskDao.update(transientInstance);
	}
	public void delete(String id) {
		// TODO Auto-generated method stub
		workTaskDao.delete(id);
	}

	
}
